import { toFail, toSuccess, useEntityManager } from "@sker/core"
import { KsAccount } from "@sker/entities"
import dayjs from "dayjs"

export default async () => {
    return await useEntityManager(async m => {
        const list = await m.createQueryBuilder()
            .select('account.user_id', 'user_id')
            .addSelect('account.ksid', 'ksid')
            .from(KsAccount, 'account')
            .where('account.status=:status', { status: '1' })
            .andWhere(`account.update_date<:update_date`, { update_date: dayjs().subtract(60, 'minute').toDate() })
            .orderBy(`random()`)
            .execute()
        if (list && list.length > 0) {
            return toSuccess(list[0])
        }
        return toFail(`暂无数据`)
    })
}